﻿using System.Collections.Generic;
using Resolve.Contracts;
using Resolve.FlagInfo;

namespace Resolve.Web
{
    public class ViewPageBase
    {
        protected ViewPageBase(IDictionary<string, object> viewData, IDictionary<string, object> model)
        {
            ViewData = viewData;
            Model = model;
        }

        public string Layout;

        public FlagCodeInFile LayoutFlagCodeInFile;

        public IDictionary<string, object> ViewData
        {
            protected get;
            set;
        }

        public IDictionary<string, object> Model
        {
            protected get;
            set;
        }

        public void LayoutProc()
        {
            if (string.IsNullOrEmpty(Layout)) return;
            LayoutFlagCodeInFile = ResolveEngineBase.CodeCompiler.CompileFile(System.Web.HttpContext.Current.Server.MapPath(Layout),
                 ViewData, Model);
        }

        public string Include(string relativePath)
        {
            ResolveEngineBase resolveEngine = new ResolveEngineForFolder();
            resolveEngine.ViewData = ViewData;
            resolveEngine.Model = Model;
            string result = resolveEngine.Resolve(System.Web.HttpContext.Current.Server.MapPath(relativePath));
            return result;
        }

        public virtual void SetLayout()
        {

        }
    }
}
